﻿import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileOutputStream {
	public static void main(String[] args) {
		//1.创建字节输出流

		OutputStream fis=null;
		try {
			fis=new FileOutputStream(new File("d:\\Hello.txt"),true);
			//2.执行写操作

			String str="好好学习java";
			byte[] words=str.getBytes();//字符串转换为字节数组

//			fis.write(words);构造方法

			fis.write(words, 0, words.length);
			System.out.println("Hello文件已更新！");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block

			e.printStackTrace();
			System.out.println("创建文件时出错");
		}finally{
			//3.关闭流

			if(fis!=null){
				try {
					fis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block

					e.printStackTrace();
				}
			}
		}



	}
}